
package jpoco.android;

import jpoco.client.*;
import android.content.Context;
import android.widget.*;

public class ContactView extends LinearLayout
{
	private Contact contact;
	private boolean expanded = false;
	private TextView tview;
	private String compactText;
	private String expandedText;
	
	public ContactView(Context context, Contact c)
	{
		super(context);
	
		this.expanded = false;
		
		this.contact = c;
		
		this.setOrientation(LinearLayout.VERTICAL);
		
		compactText = createCompact(c);
		
		expandedText = createExpanded(c);
		
		tview = new TextView(context);
		tview.setText(compactText);
		tview.setTypeface(AndroidApplication.getDefaultTypeface());
		tview.setTextSize(AndroidApplication.getDefaultFontSize());
		
		this.addView(tview);
		
	}

	public void toggle()
	{
		setExpanded(!isExpanded());
	}
	
	protected String createCompact(Contact c)
	{
		return Util.getDisplayName(c);
	}
	
	protected String createExpanded(Contact c)
	{
		return String.valueOf(c);
	}
	
	public void setExpanded(boolean b)
	{
		if (this.expanded == b)
		{
			return;
		}
		
		this.expanded = b;
		
		if (this.expanded)
		{
			this.tview.setText(expandedText);
		}
		else
		{
			this.tview.setText(compactText);
		}
	}
	
	public boolean isExpanded()
	{
		return this.expanded;
	}
	
	public Contact getContact()
	{
		return this.contact;
	}
	
}
